package com.jiepu.exercise.advanceed.chapter6;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Description: 边读边写
 * @author: xinjie
 * @date: 2020/8/7  8:46
 */
public class CopyDemo2 {
	public static void main(String[] args) throws IOException {
		// 创建文件输入流 读取文件
		// 输入流
		String path =
				"src/com/jiepu/exercise/advanceed/chapter6/poem.txt";
		FileInputStream fileInputStream = new FileInputStream(path);
		// 输出流
		String targetpath =
				"src/com/jiepu/exercise/advanceed/chapter6/poemcopy.txt";
		FileOutputStream fileOutputStream = new FileOutputStream(targetpath);

		// buff 缓冲池
		byte[] buf = new byte[128];
		int len = -1;
		// fileInputStream.read(buf)  从 buf 中读入 一个字节的数据

		while ((len = fileInputStream.read(buf)) != -1) {
			fileOutputStream.write(buf, 0, len);
		}
		fileInputStream.close();
		fileOutputStream.close();

	} // main

}

